from PIL import Image, ImageFont, ImageDraw
import os
import time
filler = str(input('输入文字:'))
grey_1 = [];grey_2 = []
fontPath=("simhei")
for text in filler: #灰度值
    word = text+text
    img = Image.new('RGB', (25,25),(255, 255, 255))# 画布颜色
    draw = ImageDraw.Draw(img)
    font = ImageFont.truetype(fontPath,24)
    draw.text((0, 0), word, font=font, fill='#000000')# 文字颜色
    grays = []
    for i in range(img.height):
        for j in range(img.width):
            gray = img.getpixel((j, i))      # 返回值可能是一个int, 也可能是一个三元组(x,y,z)
            if isinstance(gray, tuple):
                gray = (0.2126 * gray[0] + 0.7152 * gray[1] + 0.0722 * gray[2])
            grays.append(gray)
    gray = (sum(grays) / 625)
    grey_1.append(gray)
    grey_2.append(text)
print(f"{list(grey_1)}\n{list(grey_2)}")
zip_grey1_grey2 = zip(grey_1,grey_2)    #两个列表以相同顺序排列，根据grey_1
sorted_zip = sorted(zip_grey1_grey2, key=lambda x:x[0])
grey_1, grey_2 = zip(*sorted_zip)
print(f"{list(grey_1)}\n{list(grey_2)}")
grey_2 = [str(i) for i in grey_2]
grey_2.reverse()
filler = ''.join(grey_2)
print(filler)
print(filler[::-1])

while True:
    pass
